package model.mediators;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.entity.Entity;

public class WindowedInteraction extends SimpleWindowedInteraction {
	private static final long serialVersionUID = 1L;
	private LinkedList<SimpleInteractionOption> interList = new LinkedList<SimpleInteractionOption>();
	private String name;
	
	public WindowedInteraction(String name, InteractionMenuMediator parentMediator) {
		super(name, parentMediator);
	}

	public void createWindow() {
		Container pane = super.getContentPane();
		this.setLayout(new GridLayout(interList.size()+1,1,10,5));
		this.addTopTitle(name, pane);
		Iterator<SimpleInteractionOption> iter = interList.iterator();
		while(iter.hasNext()){
			addOptionButton(iter.next(), pane);
		}
		setVisible();
	}
	private void addTopTitle(String name, Container container){
		container.add(new JLabel(name));
	}
	private void addOptionButton(SimpleInteractionOption opt, Container container) {
		JButton button = new JButton(opt.getName());
        button.setMinimumSize(new Dimension(200,10));
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // TODO
            }
        });
        container.add(button);
    }
	
	public void addButton(SimpleInteractionOption option) {
		interList.add(option);
	}
	public void addButton(List<SimpleInteractionOption> options) {
		interList.addAll(options);
	}
	public void setVisible(){
		 // Get the size of the screen
	    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
	    
	    // Determine the new location of the window
	    int w = super.getSize().width;
	    int h = super.getSize().height;
	    int x = (dim.width-w)/2;
	    int y = (dim.height-h)/2;
	    
	    // Move the window
	    super.setLocation(x, y);
	    super.pack();
		super.setVisible(true);
	}

	public void showWindow() {
		// TODO Auto-generated method stub
		
	}

	public void hideWindow() {
		// TODO Auto-generated method stub
		
	}
}
